﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;

namespace BBMS.DLL.Base
{
    public class ObjectList
    {
        protected Hashtable hash = null;
        public ObjectList()
        {
            LoadData();
        }
        // added by Toan M. Ha 2009/12/07
        public virtual string getObjectName(object key)
        {
            if (key != null && hash != null && hash.ContainsKey(key))
                return ((ObjectBase)hash[key]).Name;
            return "";
        }
        // end added
        public virtual void LoadData()
        {
        }
        public virtual void Update(ObjectBase obj)
        {
            if (hash == null) return;
            if (hash.ContainsKey(obj.Key))
            {
                hash.Remove(obj.Key);
                hash.Add(obj.Key, obj);
            }
        }
        public virtual void Add(ObjectBase obj)
        {
            if (hash == null) return;
            if (!hash.ContainsKey(obj.Key))
                hash.Add(obj.Key, obj);
        }
        public virtual void Remove(ObjectBase obj)
        {
            if (hash == null) return;
            if (!hash.ContainsKey(obj.Key))
                hash.Remove(obj.Key);
        }
        public virtual ObjectBase Get(object key)
        {
            if (hash != null && hash.ContainsKey(key))
                return (ObjectBase)hash[key];
            else return null;
        }
        public virtual ICollection GetKeys()
        {
            if (hash == null) return null;
            else return hash.Keys;
        }
    }
}
